﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using TracNghiemTinHocDaiCuong.BIZ;
using TracNghiemTinHocDaiCuong.Common;
using TracNghiemTinHocDaiCuong.ThucThe;

namespace TracNghiemTinHocDaiCuong
{
    public partial class SuaCauHoi : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                CauHoi cauHoiMoi = TimCauHoi();
                ckeNoiDung.Text = cauHoiMoi.NoiDung;
                ckeDapAnA.Text = cauHoiMoi.DapAnA;
                ckeDapAnB.Text = cauHoiMoi.DapAnB;
                ckeDapAnC.Text = cauHoiMoi.DapAnC;
                ckeDapAnD.Text = cauHoiMoi.DapAnD;
                //ddlChuDe;
                //ddlDoKho
                //ddlDapAn
                ddlChuDe.DataSource = ChuDeBIZ.LayDanhSach();
                ddlChuDe.DataBind();
            }
        }

        private CauHoi TimCauHoi()
        {

            int id = Methods.ConvertNumber(Request.QueryString["ID"]);
            CauHoi cauHoiMoi = CauHoiBIZ.TimKiemTheoId(id);
            return cauHoiMoi;
        }

        protected void btnThem_Click(object sender, EventArgs e)
        {
            CauHoi cauHoi = TimCauHoi();
            CauHoi cauHoiMoi = new CauHoi();
            cauHoiMoi.MaCH = cauHoi.MaCH;
            cauHoiMoi.NoiDung = ckeNoiDung.Text;
            cauHoiMoi.DapAnA = ckeDapAnA.Text;
            cauHoiMoi.DapAnB = ckeDapAnB.Text;
            cauHoiMoi.DapAnC = ckeDapAnC.Text;
            cauHoiMoi.DapAnD = ckeDapAnD.Text;
            cauHoiMoi.MaCD = Methods.ConvertNumber(ddlChuDe.SelectedValue);
            string doKho = ddlDoKho.SelectedItem.ToString();
            if (doKho == "Dễ")
                cauHoiMoi.DoKho = "D";
            if (doKho == "Trung Bình")
                cauHoiMoi.DoKho = "T";
            if (doKho == "Khó")
                cauHoiMoi.DoKho = "K";
            cauHoiMoi.DapAn = ddlDapAn.SelectedItem.ToString();
            CauHoiBIZ.Sua(cauHoiMoi);
            lblThongBao.Text = "Bạn đã sửa câu hỏi thành công";
        }

        protected void btnXoaTuKhoa_Click(object sender, EventArgs e)
        {
            ckeNoiDung.Text = "";
            ckeDapAnA.Text = "";
            ckeDapAnB.Text = "";
            ckeDapAnC.Text = "";
            ckeDapAnD.Text = "";
        }

        protected void btnQuayLai_Click(object sender, EventArgs e)
        {
            Response.Redirect(string.Format("QuanLyCauHoi.aspx?Page={0}", Request.QueryString["Page"]));
        }
    }
}